var ResultTable = EventDispatcher.extend({

	body: null,
	ajaxEditHandlerUrl: null,
	ajaxShowHandlerUrl: null,
	refreshTableHandlerUrl: null,

	constructor: function()
	{
		this.ajaxEditHandlerUrl = $('#ajaxEditHandlerUrl').text();
		this.ajaxShowHandlerUrl = $('#ajaxShowHandlerUrl').text();
		this.refreshTableHandlerUrl = $('#refreshTableHandlerUrl').text();
		this.body = $('#resultTable').find('tbody');
        this.body.bind('click', handler(this, 'clickHandler'));
	},

    clickHandler: function(evt)
    {
        var targetElement = $(evt.target);
        evt.preventDefault();
        if ( targetElement.hasClass('edit_button') )
        {
        	this.requestEditForm(targetElement.attr('tabindex'));
        }
        else if ( targetElement.hasClass('show_button') )
        {
        	this.requestShowTable(targetElement.attr('tabindex'));
        }
    },

    requestEditForm: function(requestParam)
    {
        $.post(
            this.ajaxEditHandlerUrl,
            {request: requestParam},
            handler(this, 'editAjaxResponseHandler')
        );
    },

    requestShowTable: function(requestParam)
    {
        $.post(
                this.ajaxShowHandlerUrl,
                {spider_result_id: requestParam},
                handler(this, 'showAjaxResponseHandler')
            );
    },

    showAjaxResponseHandler: function(resp)
    {
    	this.dispatchEvent('showTableArrived', resp);
    },

    editAjaxResponseHandler: function(resp)
    {
    	this.dispatchEvent('formArrived', resp);
    },

    refresh: function()
    {
    	$.post(
    		this.refreshTableHandlerUrl,
    		handler(this, 'replaceContent')
    	);
    },

    replaceContent: function(resp)
    {
    	this.body.html(resp);
    }

});